package operations;

import book.Book;
import book.BookLiet;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookLiet bookLiet) {
        //借阅图书
        System.out.println("借阅图书！");
        Scanner input = new Scanner(System.in);
        System.out.println("请输入你要借阅的书籍名：");
        String bookName = input.nextLine();//输入要借阅的书名

        //1.遍历数组 - 看看书是否有
        int currentSize = bookLiet.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookLiet.getPos(i);
            if (bookName.equals(book.getName())) {
                book.setBorrowed(true);
                System.out.println("借阅成功！");
                return;
            }
        }
        System.out.println("没有你要借阅的书籍！");
    }
}
